<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  </head>
  <body>
    <a href="javascript:jsConfig()">jsConfig</a><br />

    <a href="javascript:wechatLogin();">wechat login</a>

    <script>
      function wechatLogin() {
        window.location.href =
          "/api/v1/wechat/redirect?callback=" +
          encodeURIComponent(location.origin + "/api/v1/wechat/login");
      }
      function jsConfig() {
        fetch("/api/v1/wechat/js-api-config?url=" + window.location.href, {
          method: "GET",
        })
          .then((res) => res.json())
          .then((res) => {
            console.log(res);
            let { data = {} } = res;

            wx.config({
              debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
              ...data,
              jsApiList: [], // 必填，需要使用的JS接口列表
            });
          });
      }
    </script>
  </body>
</html>
